﻿using UnityEditor;
using UnityEngine;

namespace Yoozoo.Managers.ResourceManagement
{
    public class BuildAppConfigUnit
    {
        public string channelName;
        public string serverVersionPath;
        public string secondaryServerVersionPath1;
        public string secondaryServerVersionPath2;
        public bool isSDK;
        public string serverListPath;
        public string maintenanceUrl;
        public string serverApiPath;
        public string serverPath;
        public bool showDebugBtn = false;
        
        public virtual void SetPlayerSettings()
        {

        }
    }

    [System.Serializable]
    public class BuildAndroidUnit : BuildAppConfigUnit
    {
        public string keystoreName;
        public string keyaliasName;
        public string companyName;
        public string productName;
        public string keystorePass;
        public string keyaliasPass;
        public string applicationIdentifier;

        public BuildAndroidUnit(
            string channelName, 
            string keystoreName, 
            string keyaliasName, 
            string companyName, 
            string productName, 
            string keystorePass, 
            string keyaliasPass, 
            string applicationIdentifier, 
            string serverVersionPath, 
            string secondaryServerVersionPath1, 
            string secondaryServerVersionPath2, 
            bool isSDK, 
            string serverListPath, 
            string maintenanceUrl, 
            string serverApiPath,
            bool showDebugBtn = false)
        {
            this.channelName = channelName;
            this.keystoreName = keystoreName;
            this.keyaliasName = keyaliasName;
            this.companyName = companyName;
            this.productName = productName;
            this.keystorePass = keystorePass;
            this.keyaliasPass = keyaliasPass;
            this.applicationIdentifier = applicationIdentifier;

            this.serverVersionPath = serverVersionPath;
            this.secondaryServerVersionPath1 = secondaryServerVersionPath1;
            this.secondaryServerVersionPath2 = secondaryServerVersionPath2;
            this.isSDK = isSDK;
            this.serverListPath = serverListPath;
            this.maintenanceUrl = maintenanceUrl;
            this.serverApiPath = serverApiPath;
            this.serverPath = serverPath;
            this.showDebugBtn = showDebugBtn;
        }

        public BuildAndroidUnit()
        {

        }

        public override void SetPlayerSettings()
        {
            PlayerSettings.Android.keystoreName = Application.dataPath + keystoreName;
            PlayerSettings.Android.keyaliasName = keyaliasName;
            PlayerSettings.companyName = companyName;
            PlayerSettings.productName = productName;
            PlayerSettings.Android.keystorePass = keystorePass;
            PlayerSettings.Android.keyaliasPass = keyaliasPass;
            PlayerSettings.Android.useCustomKeystore = true;
            PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, applicationIdentifier);
        }
    }

    [System.Serializable]
    public class BuildIOSUnit : BuildAppConfigUnit
    {
        public string companyName;
        public string productName;
        public string applicationIdentifier;
        public string appleDeveloperTeamID;
        public string iOSManualProvisioningProfileID;

        public BuildIOSUnit(
            string channelName, 
            string keystoreName, 
            string keyaliasName, 
            string companyName, 
            string productName, 
            string keystorePass, 
            string keyaliasPass, 
            string applicationIdentifier, 
            string serverVersionPath, 
            string secondaryServerVersionPath1, 
            string secondaryServerVersionPath2, 
            bool isSDK, 
            string serverListPath, 
            string maintenanceUrl, 
            string serverApiPath,
            string serverPath,
            bool showDebugBtn = false)
        {
            this.channelName = channelName;
            this.companyName = companyName;
            this.productName = productName;
            this.applicationIdentifier = applicationIdentifier;

            this.serverVersionPath = serverVersionPath;
            this.secondaryServerVersionPath1 = secondaryServerVersionPath1;
            this.secondaryServerVersionPath2 = secondaryServerVersionPath2;
            this.isSDK = isSDK;
            this.serverListPath = serverListPath;
            this.maintenanceUrl = maintenanceUrl;
            this.serverApiPath = serverApiPath;
            this.serverPath = serverPath;
            this.showDebugBtn = showDebugBtn;
        }

        public BuildIOSUnit()
        {

        }

        public override void SetPlayerSettings()
        {
            PlayerSettings.companyName = companyName;
            PlayerSettings.productName = productName;
            PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.iOS, applicationIdentifier);
            PlayerSettings.iOS.appleDeveloperTeamID = appleDeveloperTeamID;
            //PlayerSettings.iOS.iOSManualProvisioningProfileID = iOSManualProvisioningProfileID;
            PlayerSettings.iOS.appleEnableAutomaticSigning = true;
        }
    }
}
